package com.source.module_kotlin_library.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.os.SystemClock
import android.support.v7.app.AppCompatActivity
import android.text.TextUtils
import android.widget.Toast
import com.source.module_kotlin_library.R
import kotlinx.android.synthetic.main.activity_define.*
import java.util.concurrent.Executors

class KTDefineActivity : AppCompatActivity() {

    var count = 0
    var objectLock = java.lang.Object()
    var str: String? = null

    companion object {
        fun startActivity(context: Context) {
            var intent = Intent()
            intent.setClass(context, KTDefineActivity::class.java)
            context.startActivity(intent)
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_define_2)
//        setContentView(R.layout.activity_define)
//        viewGroup.setOnClickListener {
//            Toast.makeText(this@KTDefineActivity, "ViewGroup按钮点击了", Toast.LENGTH_SHORT).show()
//        }
//        btnClick.setOnClickListener {
//            Toast.makeText(this@KTDefineActivity, "View按钮点击了", Toast.LENGTH_SHORT).show()
//        }
        var newCachedThreadPool = Executors.newCachedThreadPool()
        var runnable1 = Runnable {
            run {
                synchronized(objectLock) {
                    SystemClock.sleep(2000)
                    initData()
                    objectLock.notify()
                }
            }
        }
        newCachedThreadPool.execute(runnable1)
        var runnable2 = Runnable {
            run {
                synchronized(objectLock) {
                    if (TextUtils.isEmpty(str)) {
                        objectLock.wait()
                    }
                    println("KTDefineActivity-runnable:${str}")
                }
            }
        }
        newCachedThreadPool.execute(runnable2)


    }

    private fun initData() {
        str = "你好呀"
    }
}